Application.EnableEvents =false(true)的理解 |
您所在的位置:网站首页 › private event翻译 › Application.EnableEvents =false(true)的理解 |
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow As Integer iRow = Target.Row Application.EnableEvents = False Cells(iRow, 3) = Cells(iRow, 3) + Cells(iRow, 2) Application.EnableEvents = True End Sub 这个程序的目的是要在 B2 输入新的数时,C2 会将 B2 输入的新数加上 C2 原有的数呈现在 C2 上。 照上面有加上 Application.EnableEvents = False 程序执行当然没问题。 现在你在 Application.EnableEvents = False 与 Application.EnableEvents = True 前加上「 '」看看(下面代码)。 程序前加上「 '」的目的是要使「 '」之后的文字变成说明文字,程序执行时是会跳过说明文字,不执行说明文字的内容。 程序前加上「 '」符号后,文字会变成绿色。 执行第二个程序时,你将发现 C2 不会按你所要求的,呈现结果。 这就是所谓的事件连锁反应。 Private Sub Worksheet_Change(ByVal Target As Range) Dim iRow As Integer iRow = Target.Row 'Application.EnableEvents = False Cells(iRow, 3) = Cells(iRow, 3) + Cells(iRow, 2) 'Application.EnableEvents = True End Sub 再如: 本示例在保存文件之前禁用事件,以使 BeforeSave 事件不能触发。 Application.EnableEvents = FalseActiveWorkbook.SaveApplication.EnableEvents = True |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |